package com.ml.rabbitmq.util;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @author xr-8
 * @date 2021-08-05
 * @time 16:16
 */
public class RabbitMqUtil {

    public static Channel getChannel() throws Exception {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("127.0.0.1");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("guest");
        connectionFactory.setPassword("guest");
//        connectionFactory.setVirtualHost("/ ");
        //2创建连接Connection
        Connection connection = connectionFactory.newConnection("生产者");
        //3通过连接获取通道Channel
        return connection.createChannel();
    }
}
